package com.wlyuan.open.scanner.domain.quotation;

import com.wlyuan.open.scanner.dao.entity.PriceDocDetailsDO;
import com.wlyuan.open.scanner.dao.entity.PriceOrderCacheDO;
import com.wlyuan.open.scanner.utils.mappings.MappingInvalid;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @author lijing
 * @description
 */
public class QuotationDetailConvert {

    private static final Convert CONVERT = Mappers.getMapper(Convert.class);

    @Mapper(uses = MappingInvalid.class)
    public interface Convert {

        @Mappings({
                @Mapping(target = "id", source = "detailId"),
                @Mapping(target = "quotationId", source = "detailDocid"),
                @Mapping(target = "type", source = "detailType"),
                @Mapping(target = "fromProvince", source = "detailFromprovince"),
                @Mapping(target = "fromProvinceName", source = "fromProvinceName"),
                @Mapping(target = "fromCity", source = "detailFromcity"),
                @Mapping(target = "fromCityName", source = "fromCityName"),
                @Mapping(target = "fromDistrict", source = "detailFromdistrict"),
                @Mapping(target = "fromDistrictName", source = "fromDistrictName"),
                @Mapping(target = "fromAddress", source = "detailFrom"),
                @Mapping(target = "toProvince", source = "detailToprovince"),
                @Mapping(target = "toProvinceName", source = "toProvinceName"),
                @Mapping(target = "toCity", source = "detailTocity"),
                @Mapping(target = "toCityName", source = "toCityName"),
                @Mapping(target = "toDistrict", source = "detailTodistrict"),
                @Mapping(target = "toDistrictName", source = "toDistrictName"),
                @Mapping(target = "toAddress", source = "detailTo"),
                @Mapping(target = "vehicleModel", source = "detailCartype"),
                @Mapping(target = "vehicleLength", source = "detailCarlength"),
                @Mapping(target = "vehicleWeight", source = "detailCarweight"),
                @Mapping(target = "vehicleVolume", source = "detailCarvolume"),
                @Mapping(target = "chargeMode", source = "detailUnittype"),
                @Mapping(target = "billingUnit", source = "detailUnit"),
                @Mapping(target = "price", source = "detailAmount"),
                @Mapping(target = "days", source = "detailAging"),
                @Mapping(target = "remarks", source = "detailDescription"),
                @Mapping(target = "additionType", source = "detailAdditiontype"),
                @Mapping(target = "createAt", source = "detailCreatetime"),
        })
        QuotationDetail convert(PriceDocDetailsDO source);

        List<QuotationDetail> convert(List<PriceDocDetailsDO> list);

        @Mappings({
                @Mapping(source = "price", target = "money"),
                @Mapping(source = "additionType", target = "type"),
        })
        SurchargeFee convertSurcharge(QuotationDetail money);

        List<SurchargeFee> convertSurcharge(List<QuotationDetail> source);

        @Mappings({
                @Mapping(source = "cacheAmount", target = "money"),
                @Mapping(source = "cacheComments", target = "remarks"),
                @Mapping(target = "type", expression = "java(com.wlyuan.open.scanner.utils.enums.quotation.QuotationSurchargeTypeEnum.OTHER)"),
        })
        SurchargeFee convertOrderCacheSurcharge(PriceOrderCacheDO source);

        List<SurchargeFee> convertOrderCacheSurcharge(List<PriceOrderCacheDO> source);


    }

    public static List<QuotationDetail> convert(List<PriceDocDetailsDO> creation) {
        return CONVERT.convert(creation);
    }

    public static QuotationDetail convert(PriceDocDetailsDO source) {
        return CONVERT.convert(source);
    }

    public static List<SurchargeFee> convertSurcharge(List<QuotationDetail> source) {
        return CONVERT.convertSurcharge(source);
    }

    public static List<SurchargeFee> convertOrderCacheSurcharge(List<PriceOrderCacheDO> source) {
        return CONVERT.convertOrderCacheSurcharge(source);
    }
}
